#include "Window.h"

namespace SDL
{

    Window::Window(/* args */) : running(false), gWindow(NULL)
    {
    }

    Window::~Window()
    {
        if (gWindow != NULL)
        {
            SDL_DestroyWindow(gWindow);
            gWindow = NULL;
        }
    }

    bool Window::init()
    {
        if (initSubSystem(SDL_INIT_EVERYTHING) < 0)
        {
            /* code */
        }
        else
        {

            if (initWindow("SDL Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 600, SDL_WINDOW_SHOWN) < 0)
            {
                /* code */
            }
            else
            {
                running = true;
                return true;
            }
        }
        return false;
    }

    int Window::initSubSystem(Uint32 flags)
    {
        if (SDL_Init(flags) < 0)
        {
            return -1;
        }
        return 0;
    }

    int Window::initWindow(const std::string title, int x, int y, int width, int height, Uint32 flags)
    {
        gWindow = SDL_CreateWindow(title.c_str(), x, y, width, height, flags);
        if (gWindow == NULL)
        {
            return -2;
        }
        return 0;
    }
    SDL_Window *Window::getSDLWindow() const
    {
        return gWindow;
    }
    bool Window::isOpen() const{
        return running;
    }

    void Window::close() {
        running = false;
    }
} // namespace SDL
